const router = require('express').Router()
const { wrap, log } = require('../tool')
const { User } = require('../config/sql')

router.use(wrap(async (req, res, next) => {
   if (req.userq == '401') throw '401'
   if (req.userq == '402') throw '402'
   next()
}))
router.get('/me', wrap(async (req, res) => {
   const [user] = await User.findAll({
      attributes: ['profile', 'nickname'],
      where: {
         uid: req.user.account
      }
   })
   const info = {
      code: 200,
      nickname: user.nickname,
      account: req.user.account,
      profile: user.profile,
   }
   res.send(info)
}))

// 用户信息
router.use(require('./info'))

// 用户其他
router.use(require('./user'))

// 文章管理
router.use('/article', require('./article'))
module.exports = router